<?php


namespace core\lib;

/**
 * 加载文件配置
 * Class Config
 * @package core\lib
 */
class Config
{
    public static $confMap = [];

    /**
     * 获取单文件配置
     * @param $name
     * @param $file
     * @return mixed
     */
    public static function get($name, $file)
    {
        /**
         * 1.判断配置文件是否存在
         * 2.判断配置是否存在
         * 3.缓存配置
         */
        if (isset(self::$confMap[$file])) {
            return self::$confMap[$file][$name];
        }

        $filePath = ROOT . 'core/config/' . $file . '.php';
        if (is_file($filePath)) {
            $conf = include $filePath;
            if (isset($conf[$name])) {
                self::$confMap[$file] = $conf;
                return $conf[$name];
            }
        }
        return [];
    }

    /**
     * 获取文件所有配置
     * @param $file
     * @return mixed
     */
    public static function all($file)
    {
        if (isset(self::$confMap[$file])) {
            return self::$confMap[$file];
        }

        $filePath = ROOT . 'core/config/' . $file . '.php';
        if (is_file($filePath)) {
            $conf = include $filePath;
            self::$confMap[$file] = $conf;
            return $conf;
        }
        return [];
    }
}